<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="View.*" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>

<%
UserView user = (UserView) request.getSession().getAttribute("user");
ArrayList<OrderView> orders = Controller.getAllOrderFromUser(user.getUserId());
%>

<body>
	<div id="container">
		<jsp:include page="../header.jsp" />
		<jsp:include page="../menu.jsp" />
		<div id="content">
			<table>
				<tr><th><u>Unpacked orders</u></th></tr>
									<%
					for (int i = 0; i < orders.size(); i++) {
						if (orders.get(i).getStatus() == 0) {
					%>
							<tr>
							<td><b>Order Id:</b> <%=orders.get(i).getOrderId()%></td>
							</tr>
							<tr>
								<td><u>Item:</u></td><td><u>Amount:</u></td>
							</tr>
							<%
							ArrayList<OrderItemView> itemsInOrder = orders.get(i).getItems();
							for (int j = 0; j < itemsInOrder.size(); j++) {
							%>
								<tr>
									<td><a href="/webshop/item?id=<%=itemsInOrder.get(j).getItem().getItemId()%>"><%=itemsInOrder.get(j).getItem().getName()%></a></td><td><%=itemsInOrder.get(j).getAmount()%></td>
								</tr>
							<%
							}
							%><tr><td>&nbsp;</td></tr><%
						}
					}
					%>
			</table>
			<hr />
			<table>
				<tr><th><u>Sent orders</u></th></tr>
									<%
					for (int i = 0; i < orders.size(); i++) {
						if (orders.get(i).getStatus() == 1) {
					%>
							<tr>
							<td><b>Order Id:</b> <%=orders.get(i).getOrderId()%></td>
							</tr>
							<tr>
								<td><u>Item:</u></td><td><u>Amount:</u></td>
							</tr>
							<%
							ArrayList<OrderItemView> itemsInOrder = orders.get(i).getItems();
							for (int j = 0; j < itemsInOrder.size(); j++) {
							%>
								<tr>
									<td><a href="/webshop/item?id=<%=itemsInOrder.get(j).getItem().getItemId()%>"><%=itemsInOrder.get(j).getItem().getName()%></a></td><td><%=itemsInOrder.get(j).getAmount()%></td>
								</tr>
							<%
							}
						}
						%><tr><td>&nbsp;</td></tr><%
					}
					%>
			</table>
		</div>
		<jsp:include page="../shoppingcart.jsp" />
		<jsp:include page="../footer.jsp" />
	</div>
</body>
</html>